#!/usr/bin/env node

const Koa = require('koa'),
      logger = require('koa-logger');

const app = new Koa();

app.use(async (ctx,next)=>{ 
  await next();
  const cost = ctx.response.get('cost');
  //const cost = ctx.cost;
  console.log(`${ctx.method} ${ctx.path} -${cost}ms`);
});

app.use(async (ctx,next)=>{ 
  const start = Date.now();

  await next();
  const end = Date.now();
  cx.set('cost',end-start);

});

app.use((ctx,next)=>{
  ctx.body = 'hello world!';
});

app.listen(8080);


